package com.zuipin.controller;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.zuipin.entity.OrderDetail;
import com.zuipin.entity.OrderInfo;
import com.zuipin.entity.OrderInvoiceInfo;
import com.zuipin.enums.OrderStatusEnum;
import com.zuipin.framework.annotation.Json;
import com.zuipin.framework.annotation.Jsons;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.exception.CustomException;
import com.zuipin.framework.result.Result;
import com.zuipin.service.IOrderDetailService;
import com.zuipin.service.IOrderService;
import com.zuipin.util.RegexUtils;
import com.zuipin.util.StringUtil;
import com.zuipin.vo.CloseOrderPrompt;
import com.zuipin.vo.CommentProductVo;
import com.zuipin.vo.ModityOrderVo;
import com.zuipin.vo.OrderDetailVo;
import com.zuipin.vo.OrderInfoVo;
import com.zuipin.vo.OrderSerachVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/*
 * @ApiParam(name = "srcSystemId", value = "来源系统", required = true) @RequestParam Long srcSystemId,
 * @ApiParam(name = "orderRemark", value = "订单备注", required = true) @RequestParam String orderRemark,
 * @ApiParam(name = "freightSum", value = "运费", required = true) @RequestParam BigDecimal freightSum,
 * @ApiParam(name = "useJfSum", value = "使用的积分", required = true) @RequestParam Integer useJfSum,
 * @ApiParam(name = "useCashBackSum", value = "使用的返现", required = true) @RequestParam BigDecimal useCashBackSum,
 * @ApiParam(name = "orderSum", value = "// 付款总额+运费（实际支付）", required = true) @RequestParam BigDecimal orderSum,
 * @ApiParam(name = "productPaySum", value = "商品价", required = true) @RequestParam BigDecimal productPaySum,
 * @ApiParam(name = "totalWeight", value = "运费", required = true) @RequestParam BigDecimal totalWeight,
 * @ApiParam(name = "buyerId", value = "卖家ID", required = true) @RequestParam Long buyerId,
 * @ApiParam(name = "isPayOnline", value = "是否在线支付", required = true) @RequestParam Short isPayOnline,
 * @ApiParam(name = "useRedPacketId", value = "使用的红包Id", required = false) @RequestParam Long useRedPacketId,
 * @ApiParam(name = "useRedPacketSum", value = "使用的红包金额", required = true) @RequestParam BigDecimal useRedPacketSum,
 * @ApiParam(name = "useRebateSum", value = "使用的返佣", required = true) @RequestParam BigDecimal useRebateSum,
 * @ApiParam(name = "useStoreValue", value = "使用的充值", required = true) @RequestParam BigDecimal useStoreValue,
 * @ApiParam(name = "isBrushOrder", value = "是否刷单", required = false) @RequestParam Short isBrushOrder
 */
/**
 * @description :
 * @author : xujinding
 * @date : 2017年3月24日 下午1:48:19
 */
@Api(value = "主订单-xujinding", description = "主订单-xujinding")
@Controller
@RequestMapping(value = "/order")
public class OrderInfoController {
	protected final Logger		log	= Logger.getLogger(getClass());
	@Resource
	private IOrderService		orderService;
	@Resource
	private IOrderDetailService	orderDetailService;
	
	@InitBinder("order")
	public void initBinder2(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("order.");
	}
	
	@ResponseBody
	@RequestMapping(value = "/updateOrderToPackOrDelivered", method = RequestMethod.POST)
	@ApiOperation(notes = "更新订单为打包中或已发货状态", value = "更新订单为打包中或已发货状态")
	@ApiIgnore
	public Result updateOrderToPackOrDelivered(@ApiParam(name = "orderNo", value = "订单号", required = true) @RequestParam(required = true) String orderNo,
			@ApiParam(name = "status", value = "订单状态", required = true) @RequestParam(required = true) String status,
			@ApiParam(name = "sysUserId", value = "修改人", required = false) @RequestParam(required = false) Long sysUserId,
			@ApiParam(name = "ip", value = "ip地址", required = false) @RequestParam(required = false) String ip) {
		Result res = new Result();
		log.info("orderNo=" + orderNo + "修改状态为：：" + status);
		res = orderService.updateOrderToPackOrDelivered(orderNo, status, sysUserId, ip, res);
		return res;
	}
	
	@ResponseBody
	@RequestMapping(value = "/auditOrder", method = RequestMethod.POST)
	@ApiOperation(notes = "审核订单", value = "审核订单")
	public Result auditOrder(@ApiParam(name = "orderNo", value = "订单号", required = true) @RequestParam(required = true) String orderNo,
			@ApiParam(name = "sysUserId", value = "修改人", required = true) @RequestParam(required = true) Long sysUserId,
			@ApiParam(name = "ip", value = "ip地址", required = false) @RequestParam(required = false) String ip) throws CustomException {
		Result res = new Result();
		res = orderService.auditOrder(orderNo, sysUserId, ip, res);
		return res;
		
	}
	
	/** 
	 * 验证手机和电话是否存在一个，且符合格式
	 * 
	 * @Title: validateMobilePhoneAndPhone 
	 * @author: wuyicheng
	 * @date: 2017年5月3日下午6:06:21 
	 * @param mobilePhone
	 * @param phone
	 * @return
	 * @return: boolean
	 * @throws 
	 */
	private boolean validateMobilePhoneAndPhone(String mobilePhone, String phone) {
		// 手机不能等于空且符合手机格式，或者电话不为空且符合电话格式
		// 同时为空
		if ((StringUtil.isBlank(mobilePhone)) && (StringUtil.isBlank(phone))) {
			return false;
		}
		if (StringUtil.isNotBlank(mobilePhone)) {
			// 不符合格式
			if (!RegexUtils.isMobileFuzzy(mobilePhone)) {
				return false;
			}
		}
		if (StringUtil.isNotBlank(phone)) {
			// 不符合格式
			if (!RegexUtils.isTelePhone(phone)) {
				return false;
			}
		}
		
		return true;
	}
	
	@Jsons(@Json(type = OrderInvoiceInfo.class, exclude = "createTime,createId,delFlag,updateId,updateTime"))
	@ResponseBody
	@ApiOperation(notes = "后台修改订单", value = "后台修改订单")
	@RequestMapping(value = "/modityOrder", method = RequestMethod.POST)
	@Valids({ @Valid(name = "modityOrderVo.freightSum", required = true, minValue = 0), @Valid(name = "modityOrderVo.customerRemark", required = true, maxLength = 200),
			@Valid(name = "modityOrderVo.orderRemark", required = true, maxLength = 200), @Valid(name = "modityOrderVo.sysUserId", required = true),
			@Valid(name = "modityOrderVo.orderNo", required = true, maxLength = 20), @Valid(name = "modityOrderVo.expressDeliveryName", required = true, maxLength = 20),
			@Valid(name = "modityOrderVo.expressDeliveryCode", required = true, maxLength = 10),
			@Valid(name = "modityOrderVo.newConsigneeVo.receiptName", required = true, maxLength = 20),
			@Valid(name = "modityOrderVo.newConsigneeVo.streetAddress", required = true, maxLength = 200),
			@Valid(name = "modityOrderVo.newConsigneeVo.address", required = true, maxLength = 230),
			@Valid(name = "modityOrderVo.newConsigneeVo.cityCode", required = true, minLength = 6, regex = "\\d{6}"),
			@Valid(name = "modityOrderVo.newConsigneeVo.countyCode", required = true, minLength = 6, regex = "\\d{6}"),
			@Valid(name = "modityOrderVo.newConsigneeVo.provinceCode", required = true, minLength = 6, regex = "\\d{6}"), })
	public Result modityOrder(@RequestBody ModityOrderVo modityOrderVo) throws CustomException {
		// 电话号码跟手机号码 校验
		Result res = new Result();
		boolean flag = validateMobilePhoneAndPhone(modityOrderVo.getNewConsigneeVo().getPhone(), modityOrderVo.getNewConsigneeVo().getTelephone());
		if (flag) {
			OrderInfoVo vo = new OrderInfoVo();
			vo.setCustomerRemark(modityOrderVo.getCustomerRemark());
			vo.setFreightSum(modityOrderVo.getFreightSum());
			vo.setOrderRemark(modityOrderVo.getOrderRemark());
			vo.setOrderNo(modityOrderVo.getOrderNo());
			vo.setExpressDeliveryName(modityOrderVo.getExpressDeliveryName());
			vo.setExpressDeliveryCode(modityOrderVo.getExpressDeliveryCode());
			vo.setOrderInvoiceInfo(modityOrderVo.getOrderInvoiceInfo());
			vo.setInternalDiscountSum(modityOrderVo.getInternalDiscountSum());
			
			orderService.modityOrder(vo, modityOrderVo.getNewConsigneeVo(), modityOrderVo.getSysUserId(), modityOrderVo.getIp(), res);
			res.setErrorCode(ErrorCode.SUCCESS);
		} else {
			res.setErrorCode(ErrorCode.ILLEGAL_PARAM);
			// 手机和电话必须填写其中一个
			res.setMessage("mobile phone errors or phone errors");
			res.setData(null);
		}
		return res;
	}
	
	/**
	 * @Description:取消订单
	 * @Title:
	 * @author: xujinding
	 * @throws CustomException 
	 * @date: 2017年3月27日上午10:19:38
	 */
	@Valids({ @Valid(name = "cancelReason", required = true, maxLength = 150), })
	
	@ResponseBody
	@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
	@ApiOperation(notes = "取消订单", value = "取消订单")
	public Result cancelOrder(@ApiParam(name = "payId", value = "付款号", required = true) @RequestParam(required = true) Long payId,
			@ApiParam(name = "sysUserId", value = "修改人（后台用户）", required = false) @RequestParam(required = false) Long sysUserId,
			@ApiParam(name = "cancelReason", value = "取消原因", required = true) @RequestParam(required = true) String cancelReason,
			@ApiParam(name = "ip", value = "ip地址", required = false) @RequestParam(required = false) String ip) throws CustomException {
		Result res = new Result();
		orderService.cancelOrder(payId, sysUserId, null, ip, res, cancelReason);
		return res;
	}
	
	/**
	 * @Description:新增赠品
	 * @Title:
	 * @author: xujinding
	 * @throws CustomException 
	 * @date: 2017年3月27日上午10:19:38
	 */
	@ResponseBody
	@RequestMapping(value = "/addPremiums", method = RequestMethod.POST)
	@ApiOperation(notes = "新增赠品", value = "新增赠品")
	@Valids({ @Valid(name = "proSku", required = true), @Valid(name = "productNum", required = true, minValue = 0.0001), })
	public Result addPremiums(@RequestParam(required = true) Long sysUserId, @RequestParam(required = true) String orderNo, @RequestParam(required = true) BigDecimal productNum,
			@RequestParam(required = true) String proSku) throws CustomException {
		Result res = new Result();
		OrderDetailVo orderDetailVo = new OrderDetailVo();
		orderDetailVo.setProSku(proSku);
		orderDetailVo.setProductNum(productNum);
		res = orderDetailService.addPremiums(orderNo, sysUserId, orderDetailVo);
		return res;
	}
	
	/**
	 * @Description:删除赠品
	 * @Title:
	 * @author: xujinding
	 * @throws CustomException 
	 * @date: 2017年3月27日上午10:19:38
	 */
	@ResponseBody
	@RequestMapping(value = "/delPremiums", method = RequestMethod.POST)
	@ApiOperation(notes = "删除赠品", value = "删除赠品")
	public Result delPremiums(@ApiParam(name = "orderDetailIds", value = "订单详情Id", required = true) @RequestParam(required = true) String orderDetailIds,
			@ApiParam(name = "sysUserId", value = "操作人", required = true) @RequestParam(required = true) Long sysUserId) throws CustomException {
		Result res = new Result();
		res = orderDetailService.delPremiums(orderDetailIds, sysUserId);
		return res;
	}
	
	/**
	 * @Description:确认收货
	 * @Title:
	 * @author: xujinding
	 * @date: 2017年3月27日上午9:30:29
	 */
	// @ApiIgnore
	// @ResponseBody
	// @RequestMapping(value = "/confimReceipt", method = RequestMethod.POST)
	// @ApiOperation(notes = "确认收货", value = "确认收货")
	// public Result confimReceipt(
	// @ApiParam(name = "orderNo", value = "订单号", required = true) @RequestParam(required = true) String orderNo) {
	// Result res = new Result();
	// res = orderService.confimReceipt(orderNo, null, res, "用户点击确认收货");
	// return res;
	// }
	
	/*	*//**
			* @Description:
			* @Title:
			* @author: xujinding
			* @date: 2017年3月28日上午8:57:54
			*/
	/*
	@ResponseBody
	@RequestMapping(value = "/findOrderInfoListByPage", method = RequestMethod.POST)
	@ApiOperation(notes = "查询主订单信息分页", value = "查询主订单信息分页")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "orderInfo.createName", value = "下单人", required = false, dataType = "string", paramType = "query"),
		@ApiImplicitParam(name = "orderInfo.sysId", value = "系统来源", required = false, dataType = "long", paramType = "query"),
		@ApiImplicitParam(name = "orderInfo.orderNo", value = "订单号", required = false, dataType = "string", paramType = "query"),
		@ApiImplicitParam(name = "orderInfo.orderStatus", value = "订单状态", required = false, dataType = "string", paramType = "query"),
		@ApiImplicitParam(name = "orderInfo.expressNo", value = "快递单号", required = false, dataType = "string", paramType = "query"),
		@ApiImplicitParam(name = "orderInfo.endTime", value = "截止时间", required = false, dataType = "string", paramType = "query"),
		@ApiImplicitParam(name = "orderInfo.startTime", value = "开始时间", required = false, dataType = "string", paramType = "query"),
		@ApiImplicitParam(name = "orderInfo.expressDeliveryName", value = "快递公司", required = false, dataType = "string", paramType = "query") })
	public Result<List<Map<String, Object>>> findOrderInfoListByPage(
		@Inject @ApiIgnore OrderInfoVo orderInfo) {
	Result<List<Map<String, Object>>> res = new Result<List<Map<String, Object>>>();
	List<Map<String, Object>> list = orderService.findOrderInfoListByPage(orderInfo);
	res.setData(list);
	res.setErrorCode(ErrorCode.SUCCESS);
	return res;
	}*/
	
	@RequestMapping(value = "/backOrderList", method = RequestMethod.POST)
	@ApiOperation(notes = "后台订单列表"//
			+ "</br>useStoreValue:余额"//
			+ "</br>useJfSum:实付积分"//
			+ "</br>productJfSum:商品总积分"//
			+ "", value = "后台订单列表")
	@ResponseBody
	@Valids({ @Valid(name = "orderSerachVo.sysId", required = true), @Valid(name = "orderSerachVo.pageNumber", required = true, minValue = 1),
			@Valid(name = "orderSerachVo.pageSize", required = true, minValue = 1), })
	public Result backOrderList(@RequestBody OrderSerachVo orderSerachVo) {
		Result res = new Result();
		Map<String, Object> list = orderService.backOrderList(orderSerachVo);
		res.setData(list);
		res.setErrorCode(ErrorCode.SUCCESS);
		res.setMessage("success");
		return res;
	}
	
	@Valids({ @Valid(name = "pageNumber", required = true, minValue = 1), @Valid(name = "pageSize", required = true, minValue = 1),
			@Valid(name = "device", required = true, regex = "WAP|PC"), })
	@RequestMapping(value = "/preOrderList", method = RequestMethod.POST)
	@ApiOperation(notes = "前台订单列表"//
			+ "</br>useStoreValue:余额"//
			+ "</br>useJfSum:实付积分小计"//
			+ "</br>productJfSum:商品积分小计"//
			+ "</br>products.isJfProduct:是否是积分商品"//
			+ "</br>products.jfSubtotal:积分原价小计"//
			+ "</br>products.jfPurchasePrice:积分实付小计"//
			, value = "前台订单列表")
	@ResponseBody
	public Result preOrderList(@ApiParam(name = "orderStatus", value = "订单状态", required = false) @RequestParam(required = false) String orderStatus,
			@ApiParam(name = "sysId", value = "系统Id", required = true) @RequestParam(required = true) Long sysId,
			@ApiParam(name = "memberId", value = "会员Id", required = true) @RequestParam(required = true) Long memberId,
			@ApiParam(name = "pageNumber", value = "页码", required = true) @RequestParam(required = true) int pageNumber,
			@ApiParam(name = "pageSize", value = "页长", required = true) @RequestParam(required = true) int pageSize,
			@ApiParam(name = "device", value = "设备", required = true) @RequestParam(required = true) String device) {
		Map<String, Object> list = orderService.preOrderList(orderStatus, memberId, sysId, pageNumber, pageSize, device);
		Result res = new Result();
		res.setData(list);
		res.setErrorCode(ErrorCode.SUCCESS);
		return res;
	}
	
	@RequestMapping(value = "/findStatusNum", method = RequestMethod.POST)
	@ApiOperation(notes = "各个订单状态的数量", value = "各个订单状态的数量")
	@ResponseBody
	public Result findStatusNum(@ApiParam(name = "sysId", value = "系统Id", required = true) @RequestParam(required = true) Long sysId,
			@ApiParam(name = "memberId", value = "会员Id", required = true) @RequestParam(required = true) Long memberId) {
		Map<String, Integer> map = orderService.findStatusNum(memberId, sysId);
		Result res = new Result();
		res.setData(map);
		res.setErrorCode(ErrorCode.SUCCESS);
		return res;
	}
	
	@Valids({ @Valid(name = "device", required = true, regex = "WAP|PC"), })
	@RequestMapping(value = "/orderProductList", method = RequestMethod.POST)
	@ApiOperation(notes = "订单商品列表" + //
			"</br>products.isJfProduct:是否是积分商品"//
			+ "</br>products.jfSubtotal:积分原价小计"//
			+ "</br>products.jfPurchasePrice:积分实付小计", value = "订单商品列表")
	@ResponseBody
	public Result orderProductList(@ApiParam(name = "orderId", value = "订单ID", required = true) @RequestParam(required = true) Long orderId,
			@ApiParam(name = "memberId", value = "会员ID", required = false) @RequestParam(required = false) Long memberId,
			@ApiParam(name = "device", value = "设备", required = true) @RequestParam(required = true) String device) throws CustomException {
		Result res = new Result();
		JSONObject obj = orderService.orderProductList(orderId, device, memberId);
		// Map<String, Object> map = new HashMap<String, Object>();
		// map = JSONObject.fromObject(obj.toString());
		// JSONObject json = JSONObject.fromObject(obj);
		// String s =
		// "{\"code\":0,\"message\":\"success\",\"data\":[{\"orderNo\":\"MO201704270119\",\"subOrderNo\":\"DO1704274443\",\"expressName\":\"申通E物流\",\"erpOrderId\":106325,\"expressNo\":null,\"subOrderStatus\":\"中止\",\"expressCode\":\"ST-HDFK\",\"subSendRepertory\":\"物流成品仓\"}]}";
		res.setData(obj);
		res.setErrorCode(ErrorCode.SUCCESS);
		return res;
	}
	
	@Valids({ @Valid(name = "delYes", required = true, regex = "0|1"), })
	@RequestMapping(value = "/findOrderByNo", method = RequestMethod.POST)
	@ApiOperation(notes = "根据订单编码查询订单信息（付款单跟主订单结合）"//
			+ "</br>useStoreValue:使用的余额"//
			+ "</br>useJfSum:实付积分"//
			+ "</br>isUseStoreValue:是否使用充值"//
			+ "</br>productJfSum:积分原价小计"//
			, value = "根据订单编码查询订单信息（付款单跟主订单结合）")
	@ResponseBody
	public Result findOrderByNo(@ApiParam(name = "orderNo", value = "订单编码", required = true) @RequestParam(required = true) String orderNo,
			@ApiParam(name = "memberId", value = "会员Id", required = false) @RequestParam(required = false) Long memberId,
			@ApiParam(name = "delYes", value = "1包含删除的", required = true) @RequestParam(required = true) Integer delYes) {
		Result res = new Result();
		res = orderService.getOrderAndPayInfoByOrderNo(orderNo, delYes, memberId);
		return res;
	}
	
	@RequestMapping(value = "/getStatusGroup", method = RequestMethod.POST)
	@ApiOperation(notes = "后台获取分组状态（DOING，AUDITING，FINSHED）", value = "获取分组状态")
	@ResponseBody
	public Result getStatusGroup(@ApiParam(name = "groupStatus", value = "分组（DOING，AUDITING，FINSHED）", required = false) @RequestParam(required = false) String groupStatus) {
		Result res = new Result();
		List<OrderStatusEnum> list = OrderStatusEnum.getStatusList(groupStatus);
		List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
		for (OrderStatusEnum oe : list) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("value", oe.getValue());
			map.put("name", OrderStatusEnum.getNameByValue(oe.getValue()));
			map.put("index", oe.getIndex());
			returnList.add(map);
		}
		res.setData(returnList);
		res.setErrorCode(ErrorCode.SUCCESS);
		return res;
	}
	
	@Valids({ @Valid(name = "closeReason", required = true, maxLength = 150), })
	@RequestMapping(value = "/closeOrder", method = RequestMethod.POST)
	@ApiOperation(notes = "关闭订单", value = "关闭订单")
	@ResponseBody
	public Result closeOrder(@ApiParam(name = "orderNo", value = "订单编码", required = true) @RequestParam(required = true) String orderNo,
			@ApiParam(name = "closeReason", value = "订单关闭理由", required = true) @RequestParam(required = true) String closeReason,
			@ApiParam(name = "sysUserId", value = "操作人", required = true) @RequestParam(required = true) Long sysUserId) throws CustomException {
		Result res = new Result();
		res = orderService.closeOrder(orderNo, sysUserId, closeReason);
		return res;
		
	}
	
	@RequestMapping(value = "/findOrderLog", method = RequestMethod.POST)
	@ApiOperation(notes = "获取订单日志", value = "获取订单")
	@ResponseBody
	@ApiIgnore
	public Result findOrderLog(@ApiParam(name = "orderNo", value = "订单编码", required = true) @RequestParam(required = true) String orderNo) {
		Result res = new Result();
		res = orderService.findOrderLog(orderNo);
		return res;
		
	}
	
	@RequestMapping(value = "/findOrderByIds", method = RequestMethod.POST)
	@ApiOperation(notes = "查询订单信息根据orderId（多个）", value = "查询订单信息根据orderId（多个）")
	@ResponseBody
	public Result findOrderByIds(@ApiParam(name = "ids", value = "订单id", required = true) @RequestParam(required = true) String ids) {
		Result res = new Result();
		res = orderService.getOrderByIds(ids);
		return res;
	}
	
	@RequestMapping(value = "/disb/getorderstatus", method = RequestMethod.POST)
	@ApiOperation(notes = "查询订单状态（多个）", value = "查询订单状态（多个）")
	@ResponseBody
	public Result getOrderStatus(@ApiParam(name = "data", value = "订单id", required = true) @RequestParam(required = true) String data) {
		Result res = new Result();
		Map<String, Object> map = orderService.getOrderStatus(data);
		Map<String, Object> returnMap = new HashMap<String, Object>();
		returnMap.put("result", map);
		res.setData(returnMap);
		res.setErrorCode(ErrorCode.SUCCESS);
		return res;
	}
	
	@RequestMapping(value = "/disb/getmembertotal", method = RequestMethod.POST)
	@ApiOperation(notes = "根据unionid查找醉品对应会员总消费金额", value = "根据unionid查找醉品对应会员总消费金额")
	@ResponseBody
	public Result getMemberTotal(@ApiParam(name = "data", value = "订单id", required = true) @RequestParam(required = true) String data) throws CustomException {
		Result res = new Result();
		Map<String, Object> returnMap = orderService.getMemberTotal(data);
		res.setData(returnMap);
		res.setErrorCode(ErrorCode.SUCCESS);
		return res;
	}
	
	@RequestMapping(value = "/disb/getmemberorderinfo", method = RequestMethod.POST)
	@ApiOperation(notes = "根据时间和条数，查询订单醉品分销使用", value = "根据时间和条数，查询订单醉品分销使用")
	@ResponseBody
	public Result getDisbOrderInfo(@ApiParam(name = "data", value = "订单id", required = true) @RequestParam(required = true) String data) throws ParseException {
		Result res = new Result();
		Map<String, Object> returnMap = orderService.getDisbOrderInfo(data);
		res.setData(returnMap);
		res.setErrorCode(ErrorCode.SUCCESS);
		return res;
	}
	
	@RequestMapping(value = "/findDisbOrderByNos", method = RequestMethod.POST)
	@ApiOperation(notes = "查询订单信息根据orderNo（多个）", value = "查询订单信息根据orderNo（多个）")
	@ResponseBody
	public Result findOrderByNos(@ApiParam(name = "orderNos", value = "订单编码", required = true) @RequestParam(required = true) String orderNos) {
		Result res = new Result();
		res = orderService.getOrderByNos(orderNos);
		return res;
	}
	
	@RequestMapping(value = "/orderCommentProduct", method = RequestMethod.POST)
	@ApiOperation(notes = "查询订单商品" + "</br>返回码" + "</br>0-成功" + "</br>1001-参数异常" + "</br>1004-系统异常", value = "查询订单商品")
	@ResponseBody
	@Valids({ @Valid(name = "device", required = true, regex = "WAP|PC"), })
	public Result<List<CommentProductVo>> orderCommentProduct(@ApiParam(name = "orderId", value = "订单ID", required = true) @RequestParam(required = true) Long orderId,
			@ApiParam(name = "memberId", value = "会员ID", required = false) @RequestParam(required = false) Long memberId,
			@ApiParam(name = "sysId", value = "系统id", required = true) @RequestParam(required = true) Long sysId,
			@ApiParam(name = "device", value = "设备 PC,WAP", required = true) @RequestParam(required = true) String device) {
		Result<List<CommentProductVo>> res = new Result<>();
		List<CommentProductVo> list = orderService.orderProduct(orderId, memberId, device, sysId);
		res.setErrorCode(ErrorCode.SUCCESS);
		res.setData(list);
		return res;
	}
	
	@RequestMapping(value = "/findOrderProductById", method = RequestMethod.POST)
	@ApiOperation(notes = "查询订单商品" + "</br>返回码" + "</br>0-成功" + "</br>1001-参数异常" + "</br>1004-系统异常", value = "查询订单商品")
	@ResponseBody
	@Valids({ @Valid(name = "device", required = true, regex = "WAP|PC"), })
	public Result<List<OrderDetail>> orderProduct(@ApiParam(name = "orderId", value = "订单ID", required = true) @RequestParam(required = true) Long orderId,
			@ApiParam(name = "memberId", value = "会员ID", required = false) @RequestParam(required = false) Long memberId,
			@ApiParam(name = "sysId", value = "系统id", required = true) @RequestParam(required = true) Long sysId,
			@ApiParam(name = "device", value = "设备 PC,WAP", required = true) @RequestParam(required = true) String device) {
		Result<List<OrderDetail>> res = new Result<>();
		List<OrderDetail> list = orderService.findOrderProductById(orderId, memberId, device, sysId);
		res.setErrorCode(ErrorCode.SUCCESS);
		res.setData(list);
		return res;
	}
	
	@RequestMapping(value = "/dealClosePrompt", method = RequestMethod.POST)
	@ApiOperation(notes = "关闭订单提示" + "</br>返回码" + "</br>0-成功" + "</br>1001-参数异常" + "</br>1004-系统异常", value = "关闭订单提示")
	@ResponseBody
	public Result<CloseOrderPrompt> dealClosePrompt(@ApiParam(name = "sysId", value = "系统id", required = true) @RequestParam(required = true) Long sysId,
			@ApiParam(name = "orderNo", value = "订单No", required = true) @RequestParam(required = true) String orderNo) {
		Result<CloseOrderPrompt> res = new Result<>();
		res = orderService.dealClosePrompt(orderNo);
		return res;
	}
	
	@RequestMapping(value = "/fingOrderByInvoiceId", method = RequestMethod.POST)
	@ApiOperation(notes = "根据发票id获取订单" + "</br>返回码" + "</br>0-成功" + "</br>1001-参数异常" + "</br>1004-系统异常", value = "关闭订单提示")
	@ResponseBody
	public Result<OrderInfo> fingOrderByInvoiceId(@ApiParam(name = "sysId", value = "系统id", required = true) @RequestParam(required = true) Long sysId,
			@ApiParam(name = "invoiceId", value = "发票Id", required = true) @RequestParam(required = true) Long invoiceId) {
		Result<OrderInfo> res = new Result<>();
		OrderInfo oi = orderService.findOrderInfoByInvoiceId(invoiceId);
		res.setData(oi);
		return res;
	}
}
